﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BFOAuction.BLL.Auction;
using System.Data;

namespace BFOAuction.Auction
{
    public partial class Auction : System.Web.UI.Page
    {
        #region Khai báo biến
        AppFormat.MyError objError = null;
        DTO.Config.Config objConfig = new DTO.Config.Config();

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadConfig();
                LoadProduct();
                LoadAuction();
            }
        }

        private void LoadAuction()
        {
            txtPriceIncreases.Text = string.Format("{0:#,##0}", objConfig.IncreaseValue);
            txtCost.Text = string.Format("{0:#,##0}", objConfig.CostCreateAuction);
        }

        private void LoadProduct()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("s_ID", typeof(string));
            dt.Columns.Add("s_Name", typeof(string));

            DataRow row = dt.NewRow();
            row["s_ID"] = "1";
            row["s_Name"] = "Iphone 5";
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["s_ID"] = "2";
            row["s_Name"] = "Samsung";
            dt.Rows.Add(row);

            cboProduct.DataSource = dt;
            cboProduct.DataTextField = "s_Name";
            cboProduct.DataValueField = "s_ID";
            cboProduct.DataBind();
        }

        private void LoadConfig()
        {
            objError = new AppFormat.MyError();
            
            objError = new BFOAuction.BLL.Config.BLL_Config().LoadInfo(ref objConfig);
            if (objError.IsError)
            {
                AppFormat.ShowMessage.ShowMsg(objError.MessageError);
                return;
            }

            if (objConfig == null || objConfig.s_ID.Trim().Length == 0)
                objConfig = new DTO.Config.Config();
        }

        private void SumCost()
        {
            txtCostCreateAuction.Text = string.Format("{0:#,##0}", objConfig.CostCreateAuction);
        }

        protected void btnTotalCost_Click(object sender, EventArgs e)
        {
            SumCost();
        }
    }
}